package com.txt.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

// excel 读取监听器
public class ExcelReadListener<T> extends AnalysisEventListener<T> {
    private final List<T> list = new ArrayList<>();

    // 每读取一行数据时调用
    @Override
    public void invoke(T data, AnalysisContext context) {
        list.add(data);
    }

    // 读取完成后调用
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        System.out.println("数据读取完成，共读取 " + list.size() + " 条记录。");
    }

    public List<T> get() {
        return list;
    }
}